package com.song.cloud.payment.controller;

import com.song.cloud.common.entities.CommonResult;
import com.song.cloud.common.entities.Payment;
import com.song.cloud.payment.service.paymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Author ZhangGuisong
 * @Date 2021/2/13-10:53
 */
@RestController
public class paymentController {
    @Value("${server.port}")
    private String serverPort;
    @Autowired
    private paymentService paymentService;
    @PostMapping("/payment/save")
    public CommonResult save(@RequestBody Payment payment){
        int save = paymentService.save(payment);
        if(save>0){
            return new CommonResult(200,"数据插入并保存成功"+serverPort,save);
        }else{
            return new CommonResult(444,"数据插入失败"+serverPort,save);
        }
    }
    @GetMapping("/payment/query/{id}")
    public CommonResult query(@PathVariable("id") Long id){
        Payment query = paymentService.query(id);
        if(query!=null){
            return new CommonResult(200,"数据查询成功"+serverPort,query);
        }else{
            return new CommonResult(444,"数据查询失败"+serverPort,null);
        }
    }
}
